﻿/// <reference path="../game/fourkill.util.js" />
/// <reference path="../input/init.fourkill.input.base.js" />
/// <reference path="../input/fourkill.input.gps.js" />
/// <reference path="../input/post.fourkill.input.singletons.js" />

var GpsTestsView_Orientation = Base.extend({
    initialize: function initialize() {
        this.alpha = 0;
        this.beta = 0;
        this.gamma = 0;
        this.absolute = 0;
        this.updateCount = 0;
        this.enabled = false;
    },
    isAvailable: function isAvailable() {
        return true;
    },
    enable: function enable() {
        if (!this.enabled && GlobalInputHandlers.Orientation.isAvailable() && GlobalInputHandlers.Orientation.enabled) {
            this.enabled = true;
            var self = this;
            GlobalInputHandlers.Orientation.subscribe("GpsTestsView.Orientation", self);
        }
    },
    disable: function disable() {
        if (this.enabled) {
            this.enabled = false;
            GlobalInputHandlers.Orientation.unsubscribe("GpsTestsView.Orientation");
        }
    },
    fireEvent: function fireEvent(eventName, data) {
        if (eventName == "orientation") {
            this.alpha = data.alpha;
            this.beta = data.beta;
            this.gamma = data.gamma;
            this.absolute = data.absolute;

            this.updateCount++;
            if (data.prevent) data.preventDefault();
        }
    },
    update: function update(context) {
        context.alpha = this.alpha;
        context.beta = this.beta;
        context.gamma = this.gamma;
        context.absolute = this.absolute;
    }
});
